package com.wc.算法基础课.D第四讲数学知识.求组合数.求组合数_I;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/23 20:42
 * @description https://www.acwing.com/problem/content/887/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 2010;
    /**
     * f[i][j]表示从i个里面选j个<p>
     * f[i][j] = f[i - 1][j - 1] + f[i - 1][j]<p>
     * 第i个选中了j，没选中j<p>
     */
    static int[][] f = new int[N][N];
    static int n, a, b;
    static int P = (int) 1e9 + 7;

    public static void main(String[] args) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= i; j++) {
                if (j == 0) {
                    f[i][j] = 1;
                    continue;
                }
                f[i][j] = (f[i - 1][j - 1] + f[i - 1][j]) % P;
            }
        }
        n = sc.nextInt();
        while (n-- > 0) {
            a = sc.nextInt();
            b = sc.nextInt();
            out.println(f[a][b]);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}